Problem with saving pictures in certain ways [migrated]

Posted by user132750 on Programmers See other posts from Programmers or by user132750
Published on 2014-06-04T22:06:47Z Indexed on 2014/06/05 3:38 UTC
Read the original article Hit count: 154

Filed under:

I am making a Garfield comic viewer in C#. I have a button that saves the comic on screen to the computer. However, when I compile it from Visual C# Express, it saves perfectly. When I run the exe file from the directory, I get an unhandled exception message stating "A generic error occurred in GDI+". Here is my saving code:

private void save_Click(object sender, EventArgs e)
{
     using (SaveFileDialog sfdlg = new SaveFileDialog())
     {
          sfdlg.Title = "Save Dialog";
          sfdlg.Filter = "Bitmap Images (*.bmp)|*.bmp|All files(*.*)|*.*";
          if (sfdlg.ShowDialog(this) == DialogResult.OK)
          {
              using (Bitmap bmp = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height))
              {
                   pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
                   pictureBox1.Image = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height);
                   pictureBox1.Image.Save("c://cc.Jpg");
                   bmp.Save(sfdlg.FileName);
                   pictureBox1.ImageLocation = "http://garfield.com/uploads/strips" + "/" + whole.ToString("yyyy-MM-dd") + ".jpg";
                   MessageBox.Show("Comic Saved.");
              }
          }
      }
 }

What can I do?

© Programmers or respective owner

Related posts about c#